/* 模拟高阶函数，map, every ,some */
// map
const map = (array, fn) => {
  let results = []
  for (const value of array) {
    results.push(fn(value))
  }
  return results
}

// test
/*let arr = [1,2,3,4,5,6,7,9]
arr = map(arr, v=>v*v)
console.log(arr)*/

// every
const every = (array, fn) => {
  let result = true
  for (let value of array) {
    result = fn(value)
    if (!result) {
      break
    }
  }
  return result
}

// test
// let arr = [11, 30, 12,10,9]
// let r = every(arr, v => v > 10)
// console.log(r)

// some  是否有一个满足这个条件
const some = (array, fn) => {
  let result = false
  for (const value of array) {
    result = fn(value)
    if (result) {
      break
    }
  }
  return result
}

// test
let arr = [1, 3, 4, 5]
let r = some(arr, v => v % 2 === 0)
console.log(r);
